<include file="Public:js"/>
<div class="page-group">
    <div class="page" data-page="index">
        <div class="content infinite-scroll infinite-scroll-bottom" data-distance="100" style="text-align: center">
            <div class="waterfall book_rec_div">
                <ul class="waterfall_ul">
                </ul>
            </div>
            <div class="infinite-scroll-preloader">
                <div class="preloader"></div>
            </div>
        </div>
    </div>
</div>
<script>
    $.config = {
        autoInit: true,
    }
</script>
<script src="__PUBLIC__/js/video.js"></script>
<script>
    $(function() {
        $(".swiper-container").swiper( {
                    autoplay : 5000,
                    pagination: '.swiper-pagination',
                    paginationClickable: true
        });
    });
    var loading = false;
    var maxItems = 100;
    var itemsPerLoad = 8;
    function addItems(number, lastIndex) {
        var html = '';

        $.post( "{:U('Movie/getmovies')}", {i:lastIndex, num:number},function(data) {
                var html = '';
                if (data == 0) {
                    //loading=true;
                    $.detachInfiniteScroll($('.infinite-scroll'));
                    // 删除加载提示符
                    $('.infinite-scroll-preloader').remove();
                    $('.infinite-scroll-bottom .waterfall_ul').append("<p style='text-align:center;width: 100%;display: inline-block;'>没有了</p>");
                    return;
                }
                $.each(data, function (i, item) {
                    html += '<li>' +
                            '<div class="color_white_bac book_rec_detail" >' +
                            '<img src="' + item.pic + '" alt="" style="width: 100%;height: 100px" onclick=window.location.href="'+item.detail_url+'">' +
                            '<div>' +
                            '<div class="rec_div_book_name">' + item.title + '<br /><font style="font-size:12px;color:#ACACAC">播放:'+item.log_num+'</font></div>' +
                            '</div>' +
                            '</li>';
                });
                $('.infinite-scroll-bottom .waterfall_ul').append(html);
                if ($('.waterfall_ul li').length < itemsPerLoad) {
                    $.detachInfiniteScroll($('.infinite-scroll'));
                    // 删除加载提示符
                    $('.infinite-scroll-preloader').remove();
                }
            },
                "json");
    }
    addItems(itemsPerLoad, 0);

    var lastIndex = 8;
    $(document).on('infinite', '.infinite-scroll-bottom',function() {
        if (loading) return;
        loading = true;
        setTimeout(function() {
            // 重置加载flag
            loading = false;

            if (lastIndex >= maxItems) {
                // 加载完毕，则注销无限加载事件，以防不必要的加载
                $.detachInfiniteScroll($('.infinite-scroll'));
                // 删除加载提示符
                $('.infinite-scroll-preloader').remove();
                return;
            }

            // 添加新条目
            lastIndex = $('.waterfall_ul li').length;
            addItems(itemsPerLoad, lastIndex);
            // 更新最后加载的序号
            //容器发生改变,如果是js滚动，需要刷新滚动
            $.refreshScroller();
        }, 1000);
    });

</script>